/*
 * DFCInput.cpp
 *
 *  Created on: 15/01/2011
 *      Author: Danilo
 */

#include "DFCInput.h"
#include "DFCMain.h"

//------------------------------------------------
// Nome: DFCInput()
// Desc: Construtor padr�o
// Pams: nenhum
//------------------------------------------------
DFCInput::DFCInput()
{
    pr_Main = NULL;
}

//------------------------------------------------
// Nome: ~DFCInput()
// Desc: Destrutor padr�o
// Pams: nenhum
//------------------------------------------------
DFCInput::~DFCInput()
{
    Release();
}

//------------------------------------------------
// Nome: ~DFCInput()
// Desc: Destrutor padr�o
// Pams: nenhum
//------------------------------------------------
bool DFCInput::Release()
{
    return true;
}

//------------------------------------------------
// Nome: Initialize()
// Desc: Inicializa os eventos do SDL subsystem
// Pams: nenhum
//------------------------------------------------
bool DFCInput::Initialize()
{
    // Preenche as arrays de estados de teclas com zeros
    std::fill(KeyStates, KeyStates + SDLK_LAST, 0);
    std::fill(PrevKeyStates, PrevKeyStates + SDLK_LAST, 0);

	/*
    std::fill(MyKeyStates, MyKeyStates + SDLK_LAST, false);
    std::fill(MyPrevKeyStates, MyPrevKeyStates + SDLK_LAST, false);
    */

    return true;
}

//------------------------------------------------
// Nome: ReadKeyboard()
// Desc: L� dados do teclado
// Pams: nenhum
//------------------------------------------------
bool DFCInput::ReadKeyboard(SDL_Event *Event)
{
    std::copy(KeyStates, KeyStates + SDLK_LAST, PrevKeyStates);
    Uint8* p_KeyStates = SDL_GetKeyState(&iNumKeys);
    std::copy(p_KeyStates, p_KeyStates + SDLK_LAST, KeyStates);

	/*
    std::copy(MyKeyStates, MyKeyStates + SDLK_LAST, MyPrevKeyStates);

    switch (Event->type)
    {
    case SDL_KEYDOWN:
        MyKeyStates[Event->key.keysym.sym] = true;
        break;
    case SDL_KEYUP:
        MyKeyStates[Event->key.keysym.sym] = false;
        break;
    }
    */

    return true;
}

//TO-DO:
/*!
 * L� dados do mouse
 * @return true se bem sucedido, false se houve erro
 */
//bool ReadMouse(SDL_Event *Event);

//------------------------------------------------
// Nome: Read()
// Desc: L� as entradas de teclado e mouse
// Pams: nenhum
//------------------------------------------------
bool DFCInput::Read(SDL_Event *Event)
{
    if (!ReadKeyboard(Event))
    {
        return false;
    }

    // TO-DO: ReadMouse()

    return true;
}

//TO-DO:
//------------------------------------------------
// Nome: KeyDown(const SDLKey cKeyCode)
// Desc: Verifica se tecla est� pressionada
// Pams: cKeyCode: c�digo da tecla
//------------------------------------------------
/*!
 * Verifica se tecla est� pressionada
 * @param cKeyCode: c�digo da tecla
 * @return true se a tecla estiver pressionada, false se n�o
 */
//bool KeyDown(const SDLKey cKeyCode);

//------------------------------------------------
// Nome: KeyPressed(const SDLKey cKeyCode)
// Desc: Verifica se a tecla foi pressionada
// Pams: cKeyCode: c�digo da tecla
//------------------------------------------------
bool DFCInput::KeyPressed(const SDLKey cKeyCode)
{
    if (cKeyCode <= iNumKeys)
    {
        return (!PrevKeyStates[cKeyCode] && KeyStates[cKeyCode]) ? true : false;
    }

    return false;
}

//TO-DO:
/*!
 * Verifica se a tecla foi soltada
 * @param cKeyCode: c�digo da tecla
 * @return true se a tecla tiver sido soltada, false se n�o
 */
//bool KeyReleased(const SDLKey cKeyCode);

//TO-DO: MouBtnDown
//TO-DO: MouBtnPressed
//TO-DO: MouBtnReleased
//TO-DO: SetWindowsMousePos
